<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * QQ:725636367
 * Date: 2019/4/11
 * Time: 9:52
 */

// *************** PHP7 START ***************

if(!function_exists('mysql_connect')){
    /**
     * Columns are returned into the array having the fieldname as the array
     * index.
     * @link https://php.net/manual/en/mysql.constants.php
     * @deprecated 5.5
     */
    defined('MYSQL_ASSOC')  or define ('MYSQL_ASSOC', MYSQLI_ASSOC);

    /**
     * Columns are returned into the array having a numerical index to the
     * fields. This index starts with 0, the first field in the result.
     * @link https://php.net/manual/en/mysql.constants.php
     * @deprecated 5.5
     */
    defined('MYSQL_NUM')  or   define ('MYSQL_NUM', MYSQLI_NUM);

    /**
     * Columns are returned into the array having both a numerical index
     * and the fieldname as the array index.
     * @link https://php.net/manual/en/mysql.constants.php
     * @deprecated 5.5
     */
    defined('MYSQL_BOTH')  or   define ('MYSQL_BOTH', MYSQLI_BOTH);

    /**
     * Use compression protocol
     * @link https://php.net/manual/en/mysql.constants.php
     * @deprecated 5.5
     */
    defined('MYSQL_CLIENT_COMPRESS')  or  define ('MYSQL_CLIENT_COMPRESS', MYSQLI_CLIENT_COMPRESS);

    /**
     * Use SSL encryption. This flag is only available with version 4.x
     * of the MySQL client library or newer. Version 3.23.x is bundled both
     * with PHP 4 and Windows binaries of PHP 5.
     * @link https://php.net/manual/en/mysql.constants.php
     * @deprecated 5.5
     */
    defined('MYSQL_CLIENT_SSL')  or define ('MYSQL_CLIENT_SSL', MYSQLI_CLIENT_SSL);

    /**
     * Allow interactive_timeout seconds (instead of wait_timeout) of
     * inactivity before closing the connection.
     * @link https://php.net/manual/en/mysql.constants.php
     * @deprecated 5.5
     */
    defined('MYSQL_CLIENT_INTERACTIVE')  or define ('MYSQL_CLIENT_INTERACTIVE', MYSQLI_CLIENT_INTERACTIVE);

    /**
     * Allow space after function names
     * @link https://php.net/manual/en/mysql.constants.php
     * @deprecated 5.5
     */
    defined('MYSQL_CLIENT_IGNORE_SPACE')  or  define ('MYSQL_CLIENT_IGNORE_SPACE', MYSQLI_CLIENT_IGNORE_SPACE);

    global $mysqli;
//    function mysql_pconnect($host = '', $user = '', $password = '', $database = '', $port = '', $socket = ''){
//        global $mysqli;
//        $mysqli = mysqli_connect($host, $user, $password, $database,$port,$socket);
//        return $mysqli;
//    }

    function mysql_connect($host = '', $user = '', $password = ''){
        global $mysqli;
        $mysqli = mysqli_connect($host, $user, $password);
        return $mysqli;
    }
    function mysql_select_db($dbname){
        global $mysqli;
        return mysqli_select_db($mysqli,$dbname);
    }
    function mysql_fetch_array($result,$resultType=MYSQLI_BOTH){
        return mysqli_fetch_array($result,$resultType);
    }
    function mysql_fetch_assoc($result){
        return mysqli_fetch_assoc($result);
    }
    function mysql_fetch_row($result){
        return mysqli_fetch_row($result);
    }
    function mysql_query($query,$link=null){
        global $mysqli;
        $link=$link instanceof mysqli ? $link : $mysqli;
        return mysqli_query($link,$query);
    }
    function mysql_insert_id(){
        global $mysqli;
        return mysqli_insert_id($mysqli);
    }
    function mysql_escape_string($data){
        global $mysqli;
        return mysqli_real_escape_string($mysqli, $data);
        //return addslashes(trim($data));
    }
    function mysql_affected_rows(){
        global $mysqli;
       return  mysqli_affected_rows($mysqli);
    }
    function mysql_error(){
        global $mysqli;
        return mysqli_error($mysqli);
    }
    function mysql_real_escape_string($data){
        global $mysqli;
        return mysqli_real_escape_string($mysqli,$data);
    }
    function mysql_get_server_info(){
        global $mysqli;
        return mysqli_get_server_info($mysqli);
    }
    function mysql_num_fields($result){
        return mysqli_num_fields($result);
    }
    function mysql_close(){
        global $mysqli;
        return mysqli_close($mysqli);
    }
    function mysql_num_rows($result){
        return mysqli_num_rows($result);
    }
    function mysql_numrows($result){
        return mysql_num_rows($result);
    }
    function mysql_field_name($result,$fielder){
        return mysqli_fetch_field_direct($result,$fielder)->name;
    }


}

